package com.zhoug.zmui3demo.ui;

import android.inputmethodservice.KeyboardView;
import android.os.Bundle;
import android.view.WindowManager;
import android.widget.EditText;

import com.zhoug.zmui3.keyboard.KeyboardUtils;
import com.zhoug.zmui3demo.R;

import java.util.regex.Pattern;

import androidx.appcompat.app.AppCompatActivity;

public class KeyboardActivity extends AppCompatActivity {
    private static final String TAG = ">>>KeyboardActivity";
    private EditText mEditText1;
    private EditText mEditText2;
    private EditText mEditText3;
    private KeyboardUtils keyboardUtils;

    private KeyboardView mKeyboardView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_keyboard);
        findViews();
        init();

    }


    private void findViews() {
        mEditText1 = findViewById(R.id.editText1);
        mEditText2 = findViewById(R.id.editText2);
        mEditText3 = findViewById(R.id.editText3);
        mKeyboardView = findViewById(R.id.keyboardView);
    }

    private void init() {
//        keyboardUtils = new KeyboardUtils(this,mEditText1,mKeyboardView);
//        keyboardUtils = new KeyboardUtils(this,mEditText2,mKeyboardView);
//        keyboardUtils = new KeyboardUtils(this, mKeyboardView);
        keyboardUtils = new KeyboardUtils(this);
        keyboardUtils.attachTo(mEditText2);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE,
                WindowManager.LayoutParams.FLAG_SECURE);



    }

    private String toXing(String s){
        if(s!=null && s.length()>0){
            String result="";
            for(int i=0;i<s.length();i++){
                result+="*";
            }
            return result;
        }
        return "";
    }

    private Pattern pattern=Pattern.compile("\\*+");
    private String pwd="";
    private boolean hide=false;

    @Override
    public void onBackPressed() {
        if (keyboardUtils != null && keyboardUtils.isShowing()) {
            keyboardUtils.hideSoftKeyboard();
        } else {
            super.onBackPressed();
        }
    }

}